package com.kevin.Code.BinarySearch;

/**
 * @author Vinlee Xiao
 * @Classname FindPeakElement
 * @Description Leetcode 162. 寻找峰值 二分查找 中等难度 二刷
 * @Date 2022/2/27 11:10
 * @Version 1.0
 */
public class FindPeakElement {

    /**
     * 0 1 2 3 4 5 6
     * nums = [1,2,1,3,5,6,4]
     * (0+6)/2=3
     *
     * @param nums
     * @return
     */
    public int findPeakElement(int[] nums) {

        int low = 0;
        int high = nums.length - 1;

        while (low < high) {
            int mid = (low + high) >> 1;
            if (nums[mid] > nums[mid + 1]) {
                high = mid;
            } else {
                low = mid + 1;
            }

        }
        return low;
    }

    public static void main(String[] args) {

    }
}
